package cn.com.callback

import cn.com.elite.EliteBean;
import org.apache.commons.logging.Log
import org.apache.commons.logging.LogFactory
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject

import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import java.text.SimpleDateFormat

/**
 *
 * @Title: apiZhswCreateWO
 * @Description:宝安排水系统工单数据同步接口--外部接口
 * @author: chieh
 * @date 2021-08-19 10:28:00
 *
 */

public class apiZhswCreateWO implements ServiceBackInvoke {
	private static final Log log = LogFactory.getLog(apiZhswCreateWO.class);

	public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {

		//response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json;charset=UTF-8");

		String getMethod = request.getMethod();
		log.debug("getMethod:" + getMethod);

		String inData = "";
		String outData = "";
		String dataSourceID = "dataSource";

		BufferedReader iny = null;
		if (getMethod.equals("GET")) {
			inData = request.getParameter("data");
			log.debug("原始Get请求参数:" + inData);
		} else {
			InputStreamReader reader = new InputStreamReader(request.getInputStream(), "UTF-8");
			iny = new BufferedReader(reader);
			String line;
			while ((line = iny.readLine()) != null) {
				inData += line;
			}
			log.debug("原始Post请求参数:" + inData);
		}

		try {
			// 调用处理信息
			JSONArray jsonArray = new JSONArray(inData);
			JSONObject inObject = jsonArray.optJSONObject(0);
			log.debug("处理前的Json：" + inObject.toString());

			def sToken = request.getParameter("sToken");
			if (request.getParameter("sToken") == null) {
				outData = "{\"resultcode\":\"1\",\"resultmessage\":\"处理失败(参数输入异常)\",\"data\":[]}";
				return outData;
			}
			 if (sToken != "" && sToken != null) {
			   def dsftokresult = eliteBean.chaxun_sql("select PARAMETERVALUE from SYSC_PARAMETER where PARAMETER_ID = 'SWGTOK' and MODIFIEDDATE>dateadd(HOUR,-2,GETDATE()) and PARAMETERVALUE='" + sToken + "'", "dataSource");
				log.debug("dsftokresult:"+dsftokresult.size());
				if (dsftokresult.size() > 0) {
					
					String arr_data = GetJV(inObject, "flowinst");
					String arr_att = GetJV(inObject, "att");
					String arr_extform = GetJV(inObject, "extform");
					String arr_hechaatt = GetJV(inObject, "hechaatt");
					String sys_flag = "";
					String sys_source = "";
					log.debug("flowinst：" + arr_data + "att：" + arr_att + "arr_extform：" + arr_extform + "arr_hechaatt：" + arr_hechaatt);
					//必填项校验
					//新增工单
					outData = SWGDAdd(eliteBean, sys_source, sys_flag, arr_data, arr_att, arr_extform, arr_hechaatt, dataSourceID);
					}else {
					// 包装拼接返回JSONObject
					outData = "{\"resultcode\":\"401\",\"resultmessage\":\"token已失效,请重新登录\",\"data\":[]}";
					return outData;
				}
			} else {
				outData = "{\"resultcode\":\"1\",\"resultmessage\":\"处理失败(sToken异常)\",\"data\":[]}";
				return outData;
			}
		} catch (Exception e) {
			log.error("接口处理异常" + e.getMessage());
			// 失败返回
			outData = "{\"resultcode\":\"4\",\"resultmessage\":\"处理失败(" + e.getMessage() + ")\",\"data\":[]}";

		}

		log.debug("名单接入处理完成返回结果:" + outData);

		return outData;
		
	}

	// 宝安排水工单录单处理
	public static String SWGDAdd(EliteBean eliteBean, String sys_source, String sys_flag, String inJson, String arr_att, String arr_extform, String arr_hechaatt, String dataSourceID) {

		long startTime = System.currentTimeMillis();
		log.debug("录单处理开始时间:" + startTime);

		long endTime = System.currentTimeMillis();

		String reJson = null;
		try {

			JSONArray arrJsonArray = new JSONArray(inJson);

			int arrInt = arrJsonArray.length();
			log.debug("接入List数量:" + arrInt);

			JSONArray resArray = new JSONArray();
			Map<String, String> dealMap = new HashMap<String, String>();
			Map<String, String> dealMsgMap = new HashMap<String, String>();
			
			/*
			def dsftokresult = eliteBean.chaxun_sql("select PARAMETERVALUE from SYSC_PARAMETER where PARAMETER_ID = 'SWGTOK' and MODIFIEDDATE>dateadd(HOUR,-2,GETDATE())", "dataSource");
			log.debug("查看token有效期:" + dsftokresult);
			if (dsftokresult.size() == 0) { //判断token是否过期
				endTime = System.currentTimeMillis();
				reJson = "{\"result\":\"2\",\"sErrMsg\":\"token已失效,请重新登录,调用问题处理时长(毫秒):" + (endTime - startTime) + "\"}";
				return reJson;
			}
			*/

			for (int i = 0; i < arrInt; i++) {

				JSONObject arrCustJson = arrJsonArray.getJSONObject(i);

				String eventid = GetJV(arrCustJson, "eventid"); //统一事件流水号
				String eventcode = GetJV(arrCustJson, "eventcode");//事项编码
				String service = GetJV(arrCustJson, "service");//业务类型：城管、安监、查违等
				String subservice = GetJV(arrCustJson, "subservice");//业务子类型
				String busitype3 = GetJV(arrCustJson, "busitype3");//业务类型 3

				String reg1 = GetJV(arrCustJson, "reg1");   //街道
				String reg2 = GetJV(arrCustJson, "reg2");   //社区
				String objid = GetJV(arrCustJson, "objid"); //对象编号，管理对象的 ID，可以根据它查询对象的 属性，比如城管部件的编号。
				String objname = GetJV(arrCustJson, "objname");// 对象名称
				String lgt = GetJV(arrCustJson, "lgt");//经度（加密 EPSG:900913）
				String lat = GetJV(arrCustJson, "lat");//纬度（加密 EPSG:900913）
				String place = GetJV(arrCustJson, "place");// 事发位置
				String memo = GetJV(arrCustJson, "memo");//备注
				String disc = GetJV(arrCustJson, "disc");//问题描述
				String time = GetJV(arrCustJson, "time");//事发时间
				String user = GetJV(arrCustJson, "user");//上报人
				String orgname = GetJV(arrCustJson, "orgname");//上报单位
				String flowlimit = GetJV(arrCustJson, "flowlimit");//事件时限
				String gridno = GetJV(arrCustJson, "gridno");// 网格名称
				String grid = GetJV(arrCustJson, "grid");// 网格编号
				String level = GetJV(arrCustJson, "level"); //(非管控通上报)紧急程度：一般、紧急、重大
				//转化为运营管理平台统一枚举值
				if(level=='一般') {
					level='W10002001';
				}else if(level=='紧急') {
					level='W10002001';
				}else if(level=='重大') {
					level='W10002003';
				}
				String kind = GetJV(arrCustJson, "kind");   //事件类别：事件、部件
				String reporttype = GetJV(arrCustJson, "reporttype");//报送方式：报送、抄送
				String shijianjinjichengdu = GetJV(arrCustJson, "shijianjinjichengdu");
// (管控通上报)紧急程度：apiCreate(高)、2(中)、3(低)
				String usertype = GetJV(arrCustJson, "usertype"); //如为领导上报:值为领导，否则为空字符串
				String transtag = GetJV(arrCustJson, "transtag");// 多次分拨标记，默认为 apiCreate，多次分拨 apiCreate+n
				String linkname = GetJV(arrCustJson, "linkname");
//环节名称。首次向专业处置系统推送事件时默认为 转办，此时专业处置系统新增一事件。 管控通转办的事件需由管控通系统网格员核查通 过后方能结案。核查结果也是通过“事件接收接口”来推送。当核查不通过时，推送的 linkname 为退回，此 时专业处置系统需再次办理。当核查通过时，推送的 linkname 为结案，此时专业处置系统可将事件结案。
				String hechayijian = GetJV(arrCustJson, "hechayijian");//  网格员核查意见。
				String hechashijian = GetJV(arrCustJson, "hechashijian"); //网格员核查时间
				String recuser = GetJV(arrCustJson, "recuser");// 核查人姓名


				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
				System.out.println(df.format(new Date()));// new Date()为获取当前系统时间


				String Relation_ID = UUID.randomUUID().toString();
				String dealResult = "";
				String dealMessage = "";


				//查询现有当前工单编号是否存在现有工单
				//def getSelectSQL = eliteBean.chaxun_sql("select top 1   o.workorderid as workorderid,Relation_ID,o.objectivestatus,o.curstep_id_map,se3.WORKORDERSTEPSTATUS from TABCCONSULTWORKORDER t LEFT JOIN objective o on t.Relation_ID=o.objective_guid LEFT JOIN WORKORDERSTEP3 se3 on o.objective_guid=se3.WORKORDER_GUID  where o.workorderid= '" + eventid + "'  order by se3.MODIFIEDDATE    desc", dataSourceID);
				def getSelectSQL = eliteBean.chaxun_sql("select top 1 o.workorderid as workorderid,t.Relation_ID as Relation_ID,o.curstep_id_map as curstep_id_map,o.objectivestatus as objectivestatus,t.workorder_state as workorder_state,bw.status as resultstatus from TABCCONSULTWORKORDER t LEFT JOIN objective o on t.Relation_ID=o.objective_guid LEFT JOIN BP_workordertask bw ON bw.objective_guid = t.Relation_ID where o.workorderid= '" + eventid + "' order by bw.modifytime desc", "dataSource");
				log.debug("查询当前同步的工单是否已经存在 SQL:" + getSelectSQL + " 结果数量:" + getSelectSQL.size());
				String old_Relation_ID = null;
				String curstep_id_map = null;
				String objectivestatus = null;
				String workorder_state = null;
				String resultstatus = null;
				if (getSelectSQL.size() > 0) {
					old_Relation_ID = getSelectSQL.get(0).get("Relation_ID");
					curstep_id_map = getSelectSQL.get(0).get("curstep_id_map");
					objectivestatus = getSelectSQL.get(0).get("objectivestatus");
					workorder_state = getSelectSQL.get(0).get("workorder_state");
					resultstatus = getSelectSQL.get(0).get("resultstatus");
				} else {
					old_Relation_ID = null;
				}
				//处理结果字段dealResult 1成功 其他失败，处理原则：新增是工单编号不能存在，更新是工单编号必须存在
				if (isNull(eventid) || isNull(eventcode) || isNull(service) || isNull(reg1) || isNull(place) || isNull(user) || isNull(flowlimit)) {
					dealMessage = isNullMSG("eventid", eventid) + isNullMSG("eventcode", eventcode) + isNullMSG("service", service) + isNullMSG("reg1", reg1) + isNullMSG("place", place) + isNullMSG("user", user) + isNullMSG("flowlimit", flowlimit);
					endTime = System.currentTimeMillis();
					log.warn(dealMessage);
					reJson = "{\"resultcode\":\"3\",\"resultmessage\":\"处理失败(" + dealMessage + "),,调用问题处理时长(毫秒):" + (endTime - startTime) + "\",\"data\":[]}";
					return reJson;
				} else {
//                    if (sys_flag == 'add') {
					//新建工单
					try {
						if (old_Relation_ID == null || old_Relation_ID.length() <= 0) {
							JSONArray arrJsonArray1 = new JSONArray(arr_extform);
							int arrInt1 = arrJsonArray1.length();
							log.debug("接入List1数量:" + arrInt1);
							if(arrInt1>0){
							for (int j = 0; j < arrInt1; j++) {
								JSONObject arrCustJson1 = arrJsonArray1.getJSONObject(j);
								String key = "";
								String name = "";
								String value = "";
								String isQualified = "";
								key = GetJV(arrCustJson1, "key");
								name = GetJV(arrCustJson1, "name");
								value = GetJV(arrCustJson1, "value");
								isQualified = GetJV(arrCustJson1, "isQualified");
								log.debug("key:" + key + name + value + isQualified)
								eliteBean.update("INSERT INTO rm_extform([key], [name], [value], [isQualifed],objectiveID,guid) " +
										"VALUES ('" + key + "', '" + name + "', '" + value + "', '" + isQualified + "','" + Relation_ID + "','" + Relation_ID + "');", dataSourceID);
							}
							}
							JSONArray arrJsonArray2 = new JSONArray(arr_att);
							int arrInt2 = arrJsonArray2.length();
							log.debug("接入List2数量:" + arrInt2);
							if(arrInt2>0){
							for (int j = 0; j < arrInt2; j++) {
								JSONObject arrCustJson1 = arrJsonArray2.getJSONObject(j);
								String byterem = "";
								String filename = "";
								String kind1 = "";
								String url = "";
								byterem = GetJV(arrCustJson1, "byte");
								filename = GetJV(arrCustJson1, "filename");
								kind1 = GetJV(arrCustJson1, "kind");
								url = GetJV(arrCustJson1, "url");
								log.debug("byterem:" + byterem + filename + kind1 + url)
								eliteBean.update("INSERT INTO  rm_uploadrecord (guid, objectiveID, path, name, operationtime,  operator, filesuffix, filedesc,type) VALUES " +
										"('" + Relation_ID + "','" + Relation_ID + "','" + url + "','" + filename + "',getdate() ,'智慧化网格','" + kind1 + "','" + byterem + "',1)", dataSourceID)
							}
							}
							JSONArray arrJsonArray3 = new JSONArray(arr_hechaatt);
							int arrInt3 = arrJsonArray3.length();
							log.debug("接入List3数量:" + arrInt3);
							if(arrInt3>0){
							for (int j = 0; j < arrInt3; j++) {
								JSONObject arrCustJson1 = arrJsonArray3.getJSONObject(j);
								String byterem = "";
								String filename = "";
								String kind2 = "";
								String url = "";
								byterem = GetJV(arrCustJson1, "byte");
								filename = GetJV(arrCustJson1, "filename");
								kind2 = GetJV(arrCustJson1, "kind");
								url = GetJV(arrCustJson1, "url");
								log.debug("byterem:" + byterem + filename + kind + url)
								eliteBean.update("INSERT INTO  rm_uploadrecord (guid, objectiveID, path, name, operationtime,  operator,  filesuffix,filedesc,type) VALUES " +
										"('" + Relation_ID + "','" + Relation_ID + "','" + url + "','" + filename + "',getdate() ,'智慧化网格','" + kind2 + "','" + byterem + "',2)", dataSourceID)
							}
							}
							String[] data = new String[4];
							log.debug("当前工单编号不存在新建Relation_ID:" + Relation_ID);
							data[0] = "insert into TABCCONSULTWORKORDER(business_source,RELATION_ID,system_number,eventcode,service,subservice,busitype3,reg1,community,objid,obj_name,location_x,location_y,address,remarks,description,find_time,reportingname,company_reporting,surplus_time,grid_name,submitted,urgent,kind,grid,shijianjinjichengdu,usertype,transtag,linkname,hechayijian,hechashijian,recuser,workorder_state) values" +
									"('CD38FF','" + Relation_ID + "','" + eventid + "','" + eventcode + "','" + service + "','" + subservice + "','" + busitype3 + "','" + reg1 + "','" + reg2 + "','" + objid + "','" + objname + "','" + lgt + "','" + lat + "','" + place + "','" + memo + "','" + disc + "','" + time + "','" + user + "','" + orgname + "','" + flowlimit + "','" + gridno + "','" + reporttype + "','" + level + "','" + kind + "','" + grid + "','" + shijianjinjichengdu + "','" + usertype + "','" + transtag + "','" + linkname + "','" + hechayijian + "','" + hechashijian + "','" + recuser + "',1)";
							data[1] = "Insert Into Objective (Objective_Guid, Objectivetype_Id, Handleby_Id, Handlegroup_Id, Priority_Id, Expireddate, Customer_Guid, Objectivestatus,comments, Createdby, Createddate, Modifiedby, Modifieddate, Workorderframe_Id, Category, Forecastdate, Workorderid, Objectivesubstatus, Map_Id, Curstep_Id_Map) Values " +
									"('" + Relation_ID + "', 'NPYG4A', Null, 'TEAM01', 'NORMAL', getdate(), '3                                  ','OPEN','" + disc + "','SELITE', getdate(), 'SELITE',getdate(), 'MYI3EW', 'CASE1', getdate(), '" + eventid + "', 'OPEN ', 'MYI3EW', 'O70W2B')";
							data[2] = "Insert Into Workorderstep3 (Workorder_Guid, Workorderstep_Guid, Oldhandleby_Id, Oldhandlegroup_Id, Handleby_Id, Handlegroup_Id, Workorderstepstatus, Comments, Modifieddate, Workorderstepid, Stepexpired, Child_Id, Stepstart, Cur_Expiredflag, Cur_Expiredlen, Event_Guid, From_Stepidmap, To_Stepidmap, Workstarttime, Workendtime) " +
									"Values ('" + Relation_ID + "', Newid(), 'SELITE', 'SYSTEM', '', '', 'CLOSE', '', '" + df.format(new Date()) + "', Null, '" + df.format(new Date()) + "', Null, '" + df.format(new Date()) + "', '0', '0', '', 'O70W2B', 'O70W2B', getdate(), getdate())";
							data[3] = "Insert Into Elitetask (Elitetask_Guid, Objective_Guid, Objectivetype_Id, Expectstarttime, Expectendtime, Priority, Handleby_Id, Handlegroup_Id, Createdby, Createddate, Modifiedby, Modifieddate, Comments, Customer_Guid, Customerlevel, Localtrycount, Curstepstatus, Curstep_Id, Stepforecastdate, Curstep_Id_Map, Map_Id, Objectivesubstatus, Obflag)" +
									"                    Values (Newid(), '" + Relation_ID + "', 'NPYG4A', '" + df.format(new Date()) + "', '" + df.format(new Date()) + "', 'NORMAL', Null, 'SYSTEM', 'SELITE', '" + df.format(new Date()) + "', 'SELITE', '" + df.format(new Date()) + "', '"+disc+"', '3', Null, '0', 'OPEN ', 'O70W2B', '" + df.format(new Date()) + "', 'O70W2B', 'MYI3EW', 'OPEN', '0')";
//                                data[4] = "Insert Into Workorderpath3 (Workorder_Guid, Tostepid, Handlegroup, Handleby, Modifieddate, Fromstepid, Workorderpath_Guid, Woframe_Id, Fromframeid, From_Stepidmap, To_Stepidmap, Handlerole_Id)" +
//                                        "                    Values ('" + Relation_ID + "', Null, 'System', 'SELITE', '" +  df.format(new Date()) + "', Null, Newid(), '', '', '', '', Null)";

							def dataresult = eliteBean.updateBatch(data, dataSourceID);

							log.debug("data:" + data.toString());
							log.debug("当前工单编号新建结果SQL结果:" + dataresult.toString());
						} else if (old_Relation_ID!= null&&objectivestatus=="CLOSE"&&(workorder_state=="7"||(workorder_state=="4"&&resultstatus=="1"))) {
							log.debug("objectivestatus:" + objectivestatus + "curstep_id_map:" + curstep_id_map + "Relation_ID:" + Relation_ID + "workorder_state:" + workorder_state);
							
							JSONArray arrJsonArray3 = new JSONArray(arr_hechaatt);
							int arrInt3 = arrJsonArray3.length();
							log.debug("接入List数量:" + arrInt3);
							if(arrInt3>0){
							for (int j = 0; j < arrInt3; j++) {
								JSONObject arrCustJson1 = arrJsonArray3.getJSONObject(j);
								String byterem = "";
								String filename = "";
								String kind2 = "";
								String url = "";
								byterem = GetJV(arrCustJson1, "byte");
								filename = GetJV(arrCustJson1, "filename");
								kind2 = GetJV(arrCustJson1, "kind");
								url = GetJV(arrCustJson1, "url");
								log.debug("byterem:" + byterem + filename + kind + url)
								eliteBean.update("INSERT INTO  rm_uploadrecord (guid, objectiveID, path, name, operationtime,  operator,  filesuffix,filedesc,type) VALUES " +
										"('" + Relation_ID + "','" + old_Relation_ID + "','" + url + "','" + filename + "',getdate() ,'智慧化网格','" + kind2 + "','" + byterem + "',2)", dataSourceID)
							}
							}

							String[] data = new String[8];
							log.debug("Relation_ID:" + old_Relation_ID)
							data[0] = "Insert Into TABCCONSULTWORKORDER_His Select Newid(),* From TABCCONSULTWORKORDER Where Relation_ID = '" + old_Relation_ID + "'";
							data[1] = "delete from TABCCONSULTWORKORDER where system_number ='" + eventid + "' ";
							data[2] = "insert into TABCCONSULTWORKORDER(business_source,RELATION_ID,system_number,eventcode,service,subservice,busitype3,reg1,community,objid,obj_name,location_x,location_y,address,remarks,description,find_time,reportingname,company_reporting,surplus_time,grid_name,submitted,urgent,kind,grid,shijianjinjichengdu,usertype,transtag,linkname,hechayijian,hechashijian,recuser,workorder_state) values" +
									"('CD38FF','" + old_Relation_ID + "','" + eventid + "','" + eventcode + "','" + service + "','" + subservice + "','" + busitype3 + "','" + reg1 + "','" + reg2 + "','" + objid + "','" + objname + "','" + lgt + "','" + lat + "','" + place + "','" + memo + "','" + disc + "','" + time + "','" + user + "','" + orgname + "','" + flowlimit + "','" + gridno + "','" + reporttype + "','" + level + "','" + kind + "','" + grid + "','" + shijianjinjichengdu + "','" + usertype + "','" + transtag + "','" + linkname + "','" + hechayijian + "','" + hechashijian + "','" + recuser + "',5)";
							data[3] = "Delete From Workorderpath3 Where Workorder_Guid = '" + old_Relation_ID + "' And From_Stepidmap = 'O70W2B' And To_stepidmap = 'KNGZL4'";
							data[4] = "delete From Objective where Objective_Guid='" + old_Relation_ID + "'"
							data[5] = "Insert Into Objective (Objective_Guid, Objectivetype_Id, Handleby_Id, Handlegroup_Id, Priority_Id, Expireddate, Customer_Guid, Objectivestatus,comments, Createdby, Createddate, Modifiedby, Modifieddate, Workorderframe_Id, Category, Forecastdate, Workorderid, Objectivesubstatus, Map_Id, Curstep_Id_Map) Values " +
									"('" + old_Relation_ID + "', 'NPYG4A', Null, 'TEAM01', 'NORMAL', getdate(), '3   ','REOPEN','" + disc + "','SELITE', getdate(), 'SELITE',getdate(), 'MYI3EW', 'CASE1', getdate(), '" + eventid + "', 'OPEN ', 'MYI3EW', 'O70W2B')";
							data[6] = "Insert Into Workorderstep3 (Workorder_Guid, Workorderstep_Guid, Oldhandleby_Id, Oldhandlegroup_Id, Handleby_Id, Handlegroup_Id, Workorderstepstatus, Comments, Modifieddate, Workorderstepid, Stepexpired, Child_Id, Stepstart, Cur_Expiredflag, Cur_Expiredlen, Event_Guid, From_Stepidmap, To_Stepidmap, Workstarttime, Workendtime) " +
									"Values ('" + old_Relation_ID + "', Newid(), 'SELITE', 'SYSTEM', '', '', 'REOPEN', '', '" + df.format(new Date()) + "', Null, '" + df.format(new Date()) + "', Null, '" + df.format(new Date()) + "', '0', '0', '', 'O70W2B', 'O70W2B', getdate(), getdate())";
							data[7] = "Insert Into Elitetask (Elitetask_Guid, Objective_Guid, Objectivetype_Id, Expectstarttime, Expectendtime, Priority, Handleby_Id, Handlegroup_Id, Createdby, Createddate, Modifiedby, Modifieddate, Comments, Customer_Guid, Customerlevel, Localtrycount, Curstepstatus, Curstep_Id, Stepforecastdate, Curstep_Id_Map, Map_Id, Objectivesubstatus, Obflag)" +
									"                    Values (Newid(), '" + old_Relation_ID + "', 'NPYG4A', '" + df.format(new Date()) + "', '" + df.format(new Date()) + "', 'NORMAL', Null, 'SYSTEM', 'SELITE', '" + df.format(new Date()) + "', 'SELITE', '" + df.format(new Date()) + "', '"+disc+"', '3', Null, '0', 'OPEN ', 'O70W2B', '" + df.format(new Date()) + "', 'O70W2B', 'MYI3EW', 'OPEN', '0')";

							def dataresult = eliteBean.updateBatch(data, dataSourceID);
							log.debug("data:" + data.toString());
							log.debug("当前工单编号新建结果SQL结果:" + dataresult.toString());
							//dealMessage = "当前工单编号已经存在不能新建";
							endTime = System.currentTimeMillis();
							reJson = "{\"resultcode\":\"0\",\"resultmessage\":\"重新派遣案件\",\"sID\": \"" + eventid + "\"}";
							return reJson;
						} else {
							dealResult = "3";
							dealMessage = "当前工单编号已经存在不能新建";
							endTime = System.currentTimeMillis();
							reJson = "{\"resultcode\":\"3\",\"resultmessage\":\"处理失败(" + dealMessage + ")\"}";
							return reJson;
						}
					} catch (Exception e) {
						dealResult = "3";
						dealMessage = "接口内部异常";
						log.error(dealMessage + ":" + e.getMessage());
						reJson = "{\"resultcode\":\"4\",\"resultmessage\":\"处理失败(" + dealMessage + ")\"}";
						return reJson;
					}
					log.debug("当前工单编号ID:" + eventid + " 处理结果Code:" + dealResult + " 处理结果Message:" + dealMessage);
					dealMap.put(eventid, dealResult);
					dealMsgMap.put(eventid, dealMessage);
				}

				// 将每条处理结果转换为JSONArray
				int j = 0;
				for (Map.Entry<String, String> m : dealMap.entrySet()) {
					JSONObject resObject = new JSONObject();
					resObject.put("id", m.getKey());
					resObject.put("code", m.getValue());
					resObject.put("message", dealMsgMap.get(m.getKey()).toString());
					resArray.put(j, resObject);
					j++;
				}
				//生成处理完成时间
				endTime = System.currentTimeMillis();

				// 包装拼接返回JSONObject
				reJson = "{\"resultcode\":\"0\",\"resultmessage\":\"\",\"sID\": \"" + eventid + "\"}";
			}
		} catch (JSONException e) {
			endTime = System.currentTimeMillis();
			reJson = "{\"resultcode\":\"4\",\"resultmessage\":\"处理失败(" + e.getMessage() + "),调用问题处理时长(毫秒):" + (endTime - startTime) + "\"}";
		}

		return reJson;
	}


// 解析Json值
	public static String GetJV(JSONObject inJson, String getKey) {
		String Rev_Value = null;
		try {
			Rev_Value = inJson.getString(getKey);
		} catch (Exception e) {
			try {
				Rev_Value = String.valueOf(inJson.getInt(getKey));
			} catch (Exception e1) {
				try {
					Rev_Value = String.valueOf(inJson.getJSONArray(getKey));
				} catch (Exception e2) {
					try {
						Rev_Value = String.valueOf(inJson.getJSONObject(getKey));
					} catch (Exception e3) {
						Rev_Value = "";
					}
				}
			}
		} finally {
			if (Rev_Value == null || Rev_Value.equals("null") || Rev_Value.length() <= 0) {
				Rev_Value = "";
			} else {
			}
		}
		return Rev_Value;
	}

// 非空校验isNull
	public static boolean isNull(String value) {

		boolean reFlag = true;
		if (value == "" || value.length() <= 0) {
			reFlag = true;
		} else {
			reFlag = false;
		}
		log.debug(reFlag);
		return reFlag;
	}

// 非空校验isNullMSG
	public static String isNullMSG(String key, String value) {

		String reResult = "";
		if (value == "" || value.length() <= 0) {
			reResult = key + "必填字段;";
		}
		return reResult;
	}

}
